/*
 * =====================================================================================
 *
 *       Filename:  alarm_clock.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  10/03/2010 04:48:18 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ziliang), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#include "alarm_clock.h"

class TimeIntervalComp
{
public:
	TimeIntervalComp( AlarmClock::AlarmListenerData* ald )
	{
		itsListenerData = ald;
	}

	bool operator()( const AlarmClock::AlarmListenerData* ald ) const
	{
		if( itsListenerData->itsInterval > ald->itsInterval )
		{
			return false;
		}
		return true;
	}

private:
	AlarmClock::AlarmListenerData* itsListenerData;
};


AlarmClock::AlarmClock()
	: itsLock( new CLLock() )
{
}

// insert a listener to listener list
void AlarmClock::registerAlarmListener( AlarmListener* listener, int interval, bool isRepeated );
{
	AlarmClock::AlarmListenerData* ald = 
		                   new AlarmClock::AlarmListenerData( listener, interval, isRepeated) ;
  
	itsLock->lock();
	list<AlarmListenerData*>::iterator pos = find_if( itsAlarmListners.begin(), 
                                              itsAlarmListeners.end(), TimeIntervalComp( ald ) );
  itsAlarmListeners.insert( pos, ald );
	itsLock->unLock();
}

void AlarmClock::elapse( void )
{
}

